package com.api.base.controll;
import com.api.base.model.AdminUserAdd;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.base.model.AdminUser;
import com.api.base.service.AdminUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/04/01.
*/
@PowerEnable(name = "管理员账号",url = "/admin/user")
@Api(value = "管理员账号", tags = {"管理员账号"})
@RestController
@RequestMapping("/admin/user")
public class AdminUserController extends Ctrl{
    @Resource
    private AdminUserService adminUserService;

    @ApiOperation(value = "管理员账号添加", tags = {"管理员账号"}, notes = "管理员账号添加")
    @PostMapping(value="/add",name="管理员账号添加")
    public Result add(@ApiParam AdminUserAdd adminUser) {
        adminUserService.add(adminUser);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "管理员账号删除", tags = {"管理员账号"}, notes = "管理员账号删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "管理员账号id", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/delete",name="管理员账号删除")
    public Result delete(@RequestParam Long id) {
        adminUserService.delete(id);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "管理员账号列表信息", tags = {"管理员账号"}, notes = "管理员账号列表信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "Long", paramType = "query"),
        @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "Long", paramType = "query"),
        @ApiImplicitParam(name = "disable", value = "是否禁用", dataType = "Boolean", paramType = "query"),
        @ApiImplicitParam(name = "order", value = "排序json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/list", name = "管理员账号列表信息")
    public Result list(@RequestParam(defaultValue = "") String userName,
                        @RequestParam(defaultValue = "") Long startDate,
                        @RequestParam(defaultValue = "") Long endDate,
                        @RequestParam(defaultValue = "") Boolean disable,
                       @RequestParam(defaultValue = "{}") String order,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size) {


        Map<String,Object> params = new HashMap<>();
        params.put("userName",userName);
        params.put("startDate",startDate);
        params.put("endDate",endDate);
        params.put("disable",disable);
        return adminUserService.list(params, order, page, size);
    }
}
